package org.iartisan.maven.plugin.jdbc;

import org.iartisan.maven.plugin.mavenconfig.DataSourceConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * <p>
 * 返回connection
 *
 * @author King
 * @since 2017/8/30
 */
public class JdbcConnection {

    /**
     * 获取数据库连接
     *
     * @param config 数据库配置
     * @return 数据库连接
     * @throws ClassNotFoundException 驱动类找不到
     * @throws SQLException sql异常
     */
    public static Connection getConnection(DataSourceConfig config) throws ClassNotFoundException, SQLException {
        Class.forName(config.getDriverName());
        return DriverManager.getConnection(config.getUrl(), config.getUser(), config.getPassword());
    }
}


